<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 作业：写插件
        // 第一种写法
        ;(function(){

            function Compute(opt){
                this.x = opt.firstNum || 0;
                this.y = opt.secondNum || 0;
            }

            Compute.prototype = {
                add: function(){
                    return this.x + this.y;
                },
                reduce: function(){
                    return this.x - this.y;
                },
                mul: function(){
                    return this.x * this.y;
                },
                divide: function(){
                    return this.x / this.y;
                }
            }

            window.Compute = Compute;
        })()

        var compute = new Compute({
            firstNum: 1,
            secondNum: 2
        });
        console.log(compute.add());
        console.log(compute.reduce());
        console.log(compute.mul());
        console.log(compute.divide());

        // 写法2
        ;(function(){
            function Compute(){}
            Compute.prototype ={
                add: function(x, y){
                    return x + y;
                },
                reduce: function(x, y){
                    return x - y;
                },
                mul: function(x, y){
                    return x * y;
                },
                divide: function(x, y){
                    return x / y;
                }
            }
            window.Compute1 = Compute;
        })();

        var compute1 = new Compute1();

        console.log(compute1.add(10, 20));
        console.log(compute1.reduce(10, 20));
        console.log(compute1.mul(10, 20));
        console.log(compute1.divide(10, 20));
    </script>
</body>
</html>